/*
 * MeasureUnitOT.java
 *
 * $Id: MeasureUnitOT.java,v 1.2 2009-09-17 12:11:45 mario Exp $
 */
package org.ceteca.explica.core.warehouse;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.InterfaceExplica;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.extTables.ExtTableOT;

/**
 * Store class to hold the data of a measure unit.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of measure unit data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Mario García García <mario@imagos.es>
 * Copyright (c) 2007 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class MeasureUnitOT extends BaseVO implements Serializable {
	/**
	 * Internal id of the measure unit.
	 */
	private long idMeasureUnit;
	/**
	 * Description of the measure unit.
	 */
	private String description;
	/**
	 * Version of the measure unit used by Hibernate for optimistic concurrency control.
	 */
	private Integer version = new Integer(0);
	
	private static final long serialVersionUID = 10000003;
	
	/**
	 * Default MeasureUnitOT constructor.
	 */
	public MeasureUnitOT() {
	}
	
	/**
	 * Gets the version of the measure unit used by Hibernate for optimistic concurrency control.
	 * @return Integer, version of the group.
	 */
	public Integer getVersion() {
		return version;
	}
	/**
	 * Sets up the version of the measure unit used by Hibernate for optimistic concurrency control.
	 * @param version Integer, version of the group.
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * Gets the description of the measure unit.
	 * @return String, description of the group.
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * Sets up the description of the measure unit.
	 * @param description String, description of the group.
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the identifier of the measure unit.
	 * @return String, identifier of the measure unit.
	 */
	public long getIdMeasureUnit() {
		return idMeasureUnit;
	}
	/**
	 * Sets up the identifier of the measure unit.
	 * @param idMeasureUnit String, identifier of the measure unit.
	 */
	public void setIdMeasureUnit(long idMeasureUnit) {
		this.idMeasureUnit = idMeasureUnit;
	}
	
	@Override
    public int hashCode() {
        final HashCodeBuilder hcb = new HashCodeBuilder();
        hcb.append(this.getDescription());

        return hcb.toHashCode();
    }

    
    
    @Override
    public boolean equals(Object obj) {
        boolean isEquals = false;
        try {
            final MeasureUnitOT other = (MeasureUnitOT)obj;
            final EqualsBuilder eqb = new EqualsBuilder();
            eqb.append(getDescription(), other.getDescription());
            isEquals = eqb.isEquals();

        } catch (Exception e) {
            isEquals = false;
        }

        return isEquals;
    }
    
	/**
	 * Implementation of the toString() method to show the data of the ExtFieldOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idMeasureUnit);
			result.append("\nDESCRIPTION: ");
			result.append(this.description);
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting MeasureUnitOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idMeasureUnit == id.longValue();
	}
	
	@Override
	public long getInternalId() {
		return this.idMeasureUnit;
	}

	@Override
	public String getInternalValue() {
		return this.description;
	}
	
	@Override
	public String getEntityId() {
		return InterfaceWarehouse.EXPLICA_ENTITY_MEASUREUNIT_ID;
	}

	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: MeasureUnitOT.java,v 1.2 2009-09-17 12:11:45 mario Exp $";
	}	
}
